package com.aust.lambda;

import java.util.function.Function;

public class TestLambda9 {

    /**
     * 内部调用，外部实现
     *
     * @param input
     * @param fallback
     * @param <T>
     * @param <R>
     * @return
     */
    public static <T, R> R test(T input, Function<T, R> fallback) {
        return fallback.apply(input);
    }

    public static void main(String[] args) {

        /**
         * 匿名内部类
         */
        Integer i = test("hello", new Function<String, Integer>() {
            public Integer apply(String input) {
                return input.length();
            }
        });
        System.out.println(i);

        /**
         * lambda表达式
         */
        Integer j = test("world", string -> string.length());
        System.out.println(j);

        /**
         * 方法引用
         */
        Integer k = test("world", String::length);
        System.out.println(k);

    }

}
